#include <iostream>
#include <mysql/mysql.h>
#include <string>

const std::string _host = "127.0.0.1"; //或者设置 localhost
const std::string _user = "afeng";
const std::string _password = "Hxf290764@";
const std::string _db = "c_connect_test"; //默认进入的database名字
const unsigned int _port = 3306;
const std::string _unix_socket;
const unsigned long _client_flog = 0;


int main()
{
    // 获取mysql的版本号
    std::cout << mysql_get_client_info() << std::endl;

    MYSQL* my_sql = mysql_init(nullptr);
    if (my_sql)
    std::cout << "mysql_init success" << std::endl;

    if (!mysql_real_connect(my_sql,_host.c_str(), _user.c_str(), 
    _password.c_str(), _db.c_str(), _port, _unix_socket.c_str(), _client_flog))
    {
        std::cerr << "my_socket connect fail" << std::endl;
        return 2;
    }else
    { 
        std::cout << "my_socket connect success" << std::endl;
    }
    mysql_set_character_set(my_sql, "utf8");
    std::string query = "insert  people values('张三', '12345', 1), ('李四', '520', 2)";
    // query = "delete from people where name = '张三';
    // query = 'update people set phone='1314' where id=2'

    if (mysql_query(my_sql, query.c_str()))
    {
        std::cout << "insert fail" << std::endl;
        fprintf(stderr, "错误原因：%s", mysql_error(my_sql));
    }

    MYSQL_RES* result = mysql_store_result(my_sql);
    

   mysql_close(my_sql);
}


